<template>
  <div class="level">
    <h1>医院</h1>
    <div class="content">
      <div class="left">等级</div>
      <ul class="hospital">
        <li :class="{active:activeFlag==''}" @click="changeActive('')">全部</li>
        <li v-for="level in levelArr" :class="{active:activeFlag==level.value}" :key="level.value" @click="changeActive(level.value)">{{ level.name }}</li>
      </ul>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reqHospitalAndRegion } from "@/api/home/index";
import { onMounted , ref} from "vue";
import type { HospitalLevalAndRegionResponseData } from "@/api/home/type";
onMounted(() => {
  getLevel();
});
let levelArr=ref<any>([])
// 控制点击高亮
let changeActive=(level:string)=>{
  // 高亮的响应式数据储存level数值
  activeFlag.value=level
  // 触发自定义事件
  $emit('getLevel',level);
}

let activeFlag=ref<string>('')
const getLevel = async () => {
  let result: HospitalLevalAndRegionResponseData = await reqHospitalAndRegion(
    "HosType"
  );
  if(result.code==200){
    levelArr.value=result.data;
  }
};
let $emit=defineEmits(['getLevel'])
</script>
<style lang="scss" scoped>
.level {
  color: #7f7f7f;
  h1 {
    width: 50px;
    font-weight: 900;
    margin: 10px 10px;
  }
  .content {
    display: flex;
    .left {
      margin: 0 10px;
    }
    .hospital {
      display: flex;
      li {
        margin-right: 10px;
        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>
